package artifacts;

import cartago.Artifact;
import cartago.OPERATION;
import cartago.ObsProperty;
import cartago.OpFeedbackParam;

import java.util.ArrayList;

public class KITStorageRequestArt extends Artifact {
	private ArrayList<KSRequest> ksRequests;

 
    @OPERATION public void init()  {
      defineObsProperty("requests", 0);   
      ksRequests = new ArrayList<KSRequest>();
	  defineObsProperty("count",0);
    }
	    
	@OPERATION void inc(){
		ObsProperty prop = getObsProperty("count");
		prop.updateValue(prop.intValue()+1);
		signal("tick");
	}

    @OPERATION public void storageRequestFromKIT(String kitSpecification, String document, String documentType) {
    	KSRequest ksRequest = new KSRequest(kitSpecification, document, documentType);
    	ksRequests.add(ksRequest);
    	ObsProperty property  = getObsProperty("requests");
    	property.updateValue(property.intValue()+1);
    }
    
    @OPERATION public void getStorageRequest(OpFeedbackParam<String> kitSpecification, OpFeedbackParam<String> document, OpFeedbackParam<String> documentType) {
    	ObsProperty property  = getObsProperty("requests");
    	if (ksRequests.size()> 0){
    		KSRequest ksRequest = ksRequests.get(ksRequests.size()-1);
    	   	property.updateValue(property.intValue()-1);
    	   	kitSpecification.set(ksRequest.getKitSpecification());
    	   	document.set(ksRequest.getDocument());
    	   	documentType.set(ksRequest.getDocumentType());
    	}
   }
}

